from sklearn.datasets import load_breast_cancer
from sklearn.decomposition import PCA
import numpy as np
import matplotlib.pyplot as plt

data = load_breast_cancer(True)
x = data[0]
y = data[1]

n_dim = 2
dc = PCA(n_dim)
x_dc = dc.fit_transform(x)
cmap = plt.cm.get_cmap('rainbow', n_dim)
plt.scatter(x_dc[:, 0], x_dc[:, 1], s=1, c=y, cmap=cmap)

print('特征向量',dc.components_)
print('特征值',dc.explained_variance_)
print('特征值方差所占比例',dc.explained_variance_ratio_)

plt.show()